package com.fz.study.project.service.impl;

import com.fz.study.project.entity.dto.StudentCourseDto;
import com.fz.study.project.exception.BizException;
import com.fz.study.project.mapper.StudentCourseMapper;
import com.fz.study.project.service.IStudentCourseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Objects;
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2024-02-19
 */
@Service
public class StudentCourseServiceImpl extends ServiceImpl<StudentCourseMapper, StudentCourseDto> implements IStudentCourseService {

    @Override
    public void chooseCourse(StudentCourseDto studentCourseDto) {
        if (Objects.isNull(studentCourseDto)){
            BizException.throwBizException("传递的数据不能为空！");
        }
        Integer courseId = studentCourseDto.getCourseId();
        StudentCourseDto count = lambdaQuery().in(StudentCourseDto::getCourseId, courseId).one();
        if (!Objects.isNull(count)){
            BizException.throwBizException("该课程学生已经选择！");
        }
        save(studentCourseDto);
    }
}
